<?php
class Crawler extends CI_Controller
{
    public function  __construct()
    {
        parent::__construct();
    }

    public function initzipcode()
    {
        $this->load->library('mongo_db');
        $this->load->model('ZipCodeModel');

        $key = array();

        $handle = fopen('data/zipcode.csv', 'r+');
        while(($row = fgetcsv($handle, 0)) !== FALSE) {
            if(strlen($row[0]) == 5) {
                $key[] = $row[0];
                //$data = array('_id' => $row[0]);
                //$this->ZipCodeModel->insert($data);
            }
        }

        $key = array_unique($key);

        foreach ($key as $id) {
            $data = array('_id' => "$id");
            //$this->ZipCodeModel->insert($data);
            $this->mongo_db->insert('zipcode', $data);
        }

        echo "End !";
    }
}
?>
